<?php

namespace app\index\controller;

use think\Cache;
use think\Session;
use think\Db;

class Common extends \think\Controller {

    /**
     * 前置方法
     */
    public function _initialize() {

        if (Session::get('user_id') && Session::get('user_uid') && Session::get('userinfo')) {
            if (input('param.user_id') == Session::get('user_id') && input('param.user_uid') == Session::get('user_uid')) {
                $this->user_id = Session::get('user_id');
                $this->user_uid = Session::get('user_uid');
                $this->app_flag = Session::get('app_flag');
                $this->userinfo = Session::get('userinfo');
            } else {
                return retData([], '1008', '非法请求');
            }
        } else {
           
            return retData([], '1009', '用户未登录');
        }
    }

    /**
     * 获取用户列表
     * @param type $arr
     * @param type $select
     * @param type $type 0 user_id,1=>user_uid
     */
    public function getUserById($arr, $type = 0, $select = '') {
        $data = [];
        if ($type == 0) {
            $data = Db::name('chat_userinfo')->whereIn('user_id', $arr)->select($select);
        } else {
            $data = Db::name('chat_userinfo')->whereIn('user_uid', $arr)->select($select);
        }
        return $data;
    }
    
    /**
     * 生成唯一订单号
     * @param type $ext 前缀
     * @return type
     */
    public function orderId($ext){
        return $ext.date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
    }
}
